package com.cj.service.impl;

import com.cj.dao.VisitorDao;
import com.cj.po.PageInfo;
import com.cj.po.Visitor;
import com.cj.service.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service("visitorService")
@Transactional
public class VisitorServicelmpl implements VisitorService {
    // 注入studentDao
    @Autowired
    private VisitorDao visitorDao;
    @Override
    public PageInfo<Visitor> findPageInfo(String v_name, String v_phone,String v_dormIToryId, String v_dormBuilding, Date create_time,  Integer pageIndex, Integer pageSize) {
        PageInfo<Visitor> pi = new PageInfo<Visitor>();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = visitorDao.totalCount(v_name,v_phone, v_dormIToryId, v_dormBuilding,  create_time);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //每一页显示学生信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Visitor> studentList =	visitorDao.getVisitorList( v_name,v_phone, v_dormIToryId,  v_dormBuilding, create_time,
                    (pi.getPageIndex()-1)*pi.getPageSize(),pi.getPageSize());
            pi.setList(studentList);
        }
        return pi;
    }



    @Override
    public List<Visitor> getAll() {
        return visitorDao.getAll();
    }

    @Override
    public int deleteVisitor(Integer v_id) {
        return visitorDao. deleteVisitor(v_id);
    }

    @Override
    public int addVisitor(Visitor visitor) {
        return visitorDao.addVisitor(visitor);
    }

    @Override
    public int updateVisitor(Visitor visitor) {
        return visitorDao.updateVisitor(visitor);
    }

    @Override
    public Visitor findVisitorById(Integer v_id) {
        return visitorDao. findVisitorById(v_id);
    }
}
